define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    let course_id = $('#course_id').val();
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coursechapter/index' + location.search,
                    add_url: 'coursechapter/add/course_id/' + course_id,
                    edit_url: 'coursechapter/edit',
                    //del_url: 'coursechapter/del',
                    multi_url: 'coursechapter/multi',
                    import_url: 'coursechapter/import',
                    table: 'course_chapter',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'sort',
                queryParams: function (params) {
                    params.course_id = course_id;
                    return params;
                },
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'id',
                            title: __('大章编号')
                        },
                        {field: 'name', title: __('大章名称')},
                        {
                            field: 'course_id',
                            title: __('课程编号'),
                            visible: false,
                            renderDefault:true,
                        },
                        {
                            field: 'status',
                            title: __('状态'),
                            formatter: Table.api.formatter.status,
                            searchList: {1: __('Normal'), 2: __('Hidden')}
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '小节管理',
                                    title: '小节管理',
                                    icon: 'fa fa-bookmark',
                                    classname: 'btn btn-xs btn-primary btn-addtabs',
                                    url: function (row) {
                                        return 'coursechaptersection/index/pid/' + row.id;
                                    },
                                }
                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
